package com.isunland.managesystem.common;

import android.content.Context;
import com.android.volley.VolleyError;
import com.google.gson.Gson;
import com.isunland.managesystem.entity.FunctionObject;
import com.isunland.managesystem.entity.HintNumberOriginal;
import com.isunland.managesystem.utils.ConfigUtil;
import com.isunland.managesystem.utils.MyStringUtil;
import java.util.HashMap;

/**
 * 对象功能:
 * 开发公司: 北京信普达系统工程有限公司
 * 开发人员: wangyanan
 * 创建时间: 2017/6/30 15:30
 */

public class HintResponse extends VolleyResponse {
  private HashMap<Integer, FunctionObject> mMap;
  private CallBack mCallBack;

  public HintResponse(Context context, CallBack callBack) {
    this.mMap = ConfigUtil.newInstance(context).getMap();
    this.mCallBack = callBack;
  }

  @Override public void onVolleyResponse(String response) {
    HintNumberOriginal[] foos = new Gson().fromJson(response, HintNumberOriginal[].class);
    /** 部门和计划审批要加起来计算*/

    int hintApprove = 0;
    for (HintNumberOriginal foo : foos) {
      int hintCode = MyStringUtil.valueOfInt(foo.getMessage(), 0);
      int hintNumber = MyStringUtil.valueOfInt(foo.getCount(), 0);
      //特殊处理部门和计划审批
      if (hintCode == 7) hintApprove += hintNumber;
      if (hintCode == 8) hintApprove += hintNumber;
      for (FunctionObject config : mMap.values()) {
        if (hintCode == config.getHintCode()) {
          config.setHintNumber(hintNumber);
        }
      }
    }
    mMap.get(33).setHintNumber(hintApprove);
    //更新 mAdapter
    if (mCallBack != null) mCallBack.onSuccess();
  }

  @Override public void onVolleyError(VolleyError arg0) {
  }

  @Override public boolean ifToastError() {
    return false;
  }

  public interface CallBack {
    void onSuccess();
  }
}
